<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://amc.af.mil/portal-el" prefix="portal" %>
<%@ taglib uri="http://amc.af.mil/radtaglibrary" prefix="rad" %>
<%@ taglib prefix="display" uri="http://displaytag.sf.net" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="html" uri="http://struts.apache.org/tags-html-el" %>

<html>
<head>
    <title>User Management</title>
</head>

<body>

<rad:useBean id="userViewHelper"/>
<rad:useBean id="organizationViewHelper"/>

<c:choose>
    <c:when test="${sessionScope.organizationId ne 0}">
        <c:set var="userList" value="${userViewHelper.allByOrganization2}"/>
    </c:when>
    <c:otherwise>
        <c:set var="userList" value="${userViewHelper.all}"/>
    </c:otherwise>
</c:choose>

<div id="portal-left-bar">
    <jsp:include page="../../navigation/navigationMenu.jsp"/>
</div>

<div id="portal-content">
    <portal:box title="User Management" style="width:800px">

        <portal:subSection title="Organization">
            <p>
                <html:form action="/organization/changeOrganization.do">
                    <label for="organizationId">Select Organization</label>
                    <html:select property="organizationId" styleId="organizationId">
                        <html:optionsCollection name="organizationViewHelper"
                                                property="all"
                                                value="id"
                                                label="name"/>
                    </html:select>
                    <html:submit value="Select Organization"/>
                </html:form>
            </p>
        </portal:subSection>

        <portal:subSection title="Users">
            <c:choose>
                <c:when test="${sessionScope.organization ne 0 || sessionScope.organization ne null}">
                    <display:table
                            name="userViewHelper.allByOrganization2"
                            style="width:100%"
                            excludedParams="method"
                            id="user">
                        <display:column title="Name">
                            <c:out value="${user.displayName}"/>
                        </display:column>
                        <display:column title="Organization">
                            <c:out value="${user.assignedOrganization.name}"/>
                        </display:column>
                        <display:column title="Items Assigned" style="{text-align: center}">
                            <c:out value="${user.itemCount}" />
                        </display:column>
                        <display:column title="Items Hand Receipted">

                        </display:column>
                        <display:column title="Actions" style="text-align:center">
                            <html:link href="viewUserProfile.do?userId=${user.id}">Profile</html:link>
                            <html:link href="viewEditUser.do?userId=${user.id}">Edit</html:link>
                            <html:link href="equipmentItem/sendStatusEmail.do?userId=${user.id}">Send Status</html:link>
                        </display:column>
                    </display:table>
                </c:when>
                <c:otherwise>
                    <display:table
                            name="userViewHelper.all"
                            style="width:100%"
                            excludedParams="method"
                            id="user">
                        <display:column title="Name">
                            <c:out value="${user.displayName}"/>
                        </display:column>
                        <display:column title="Organization">
                            <c:out value="${user.assignedOrganization.name}"/>
                        </display:column>
                        <display:column title="Actions">
                            <html:link href="viewUserProfile.do?userId=${user.id}">Profile</html:link>
                            <html:link href="viewEditUser.do?userId=${user.id}">Edit</html:link>
                            <html:link href="#" onclick="javascript:sendStatusEmail(${user.id});">Send
                                Status</html:link>
                        </display:column>
                    </display:table>
                </c:otherwise>
            </c:choose>
        </portal:subSection>
    </portal:box>
</div>

</body>
</html>